package cn.fxc;

import org.apache.commons.math3.stat.descriptive.moment.Mean;
import org.apache.commons.math3.stat.descriptive.moment.Variance;
import tech.tablesaw.api.Table;
import tech.tablesaw.plotly.Plot;
import tech.tablesaw.plotly.components.Figure;
import tech.tablesaw.plotly.components.Layout;
import tech.tablesaw.plotly.traces.HistogramTrace;

public class NormalHistogram {

    double[] samples;

    public double[] getSamples() {
        return samples;
    }

    public void setSamples(double[] samples) {
        this.samples = samples;
    }

    public void showHistogram(){

        double mean = new Mean().evaluate(samples);
        System.out.println("均值: "+mean);
        double sd = Math.sqrt(new Variance().evaluate(samples));
        System.out.println("标准差: "+sd);
        System.out.println("样本数量: "+samples.length);
        Layout layout =
                Layout.builder().title("Percent Histogram of samples").build();
        HistogramTrace trace =
                HistogramTrace.builder(samples).build();

        Plot.show(new Figure(layout, trace));
    }

    public static void main(String[] args) {
        NormalHistogram normalHistogram = new NormalHistogram();
        normalHistogram.setSamples(new double[]{1215.79,1071.83,1231.25,1224.03,1145.04,1237.43,1141.86,1352.61,1044.33,1234.77,1114.9,1356.04,1256.22,1295.33,1243.79,1255.62,1263.61,1327.04,1370.65,1177.6,1130.55,1335.57,1160.07,1257.08,1329.73,1286.74,1155.73,1070.7,1271.07,1155.32,1273.69,1317.31,1150.15,1208.5,1314.87,1282.07,1276.57,1229.51,1300.3,1177.32,1160.95,1093.36,1135.16,1359.03,1184.25,1123.07,1319.46,1208.55,1149.76,1355.47,1240.46,1282.83,1223.81,1248.94,1267.17,1256,1341.08,1510.35,1256.53,1262.41,1187.32,1342.02,1346.65,1422.32,1166.29,1356.84,1235.8,1413.94,1244.2,1286.64,1130.44,1281.16,1247.88,1291.82,1225.07,1214.48,1227.56,1295.73,1296.05,1287.07,1210.13,1262.04,1238.68,1240.36,1358.89,1201.33,1319.96,1330.31,1200.4,1274.12,1255.55,1243.11,1267.78,1151.56,1203.85,1239.09,1263.95,1459.85,1108.45,1250.5});
        normalHistogram.showHistogram();
    }
}
